{% load staticfiles %}
    <!-- Footer -->
    <footer>
        <div class="container-fluid center">
            <a href="#">Back to the top</a>
        </div>
    </footer>
    <div id="footer-extra">
        <div class="container-fluid center">
            <div>&copy;2010-2018 <a href="https://www.cuckoosandbox.org" target="_blank">Cuckoo Sandbox</a></div>
        </div>
    </div>

    <!-- feedback form modal -->
    {% include "analysis/pages/feedback/form.html" %}

    <!-- cuckoo freeze-page loader -->
    <div class="page-freeze" id="page-freeze-container">
        <div class="page-freeze__graphic">
            <img src="{% static "graphic/cuckoo-coffee-cup.png" %}" alt="Cuckoo" />
        </div>
        <div class="page-freeze__animation">
            <!-- spinner -->
            <div class="page-freeze__spinner">
                <div class="page-freeze__spinner--c1"></div>
                <div class="page-freeze__spinner--c2"></div>
            </div>
        </div>
        <div class="page-freeze__context">
            <p class="page-freeze__message">We're processing your submission... This could take a few seconds.</p>
            <div class="page-freeze__options hidden">
                <button class="btn btn-default btn-lg close-page-freeze">Close</button>
            </div>
        </div>
    </div>

    <!-- HIGHLIGHT (_office.html, _pdf.html) -->
    <script>
        $(document).ready(function() {
          if(!window.hljs) return;
          hljs.initHighlightingOnLoad();
        });
    </script>

    <!-- RECENT PAGE CODE (analysis/index.html) -->
    <script>

        $(document).ready(function() {

            // only do this if we are on the recent page
            if(!$('table#recent').length) return;

            var recent;

            $('body').on('click', 'div.nav_container>div', function() {

                var btn_id = $(this).find("a").attr("data-filter");
                var btn_active = $(this).attr('class');
                var btn_categories = ["cat_files", "cat_urls"];

                if($('a[data-filter^="score"]', this).length) {
                    var score_choice = $(this).find('a').attr('data-filter');

                    $('.nav_container>div#item>a[data-filter^="score"]').each(function(i, obj){
                        obj = $(obj);
                        var uid = obj.attr('data-filter');

                        if(uid != score_choice){
                            obj.parent().removeClass('active');
                        }
                    });
                }

                if(!btn_active){
                    // when a category button is clicked, force deselection of adjacent categories
                    if(btn_id.startsWith("cat_")){
                        btn_categories.forEach(function (category) {
                            if (category != btn_id) {
                                category = $('.nav_container>div#item>a[data-filter="' + category + '"]').parent();

                                if (category.hasClass("active")) { category.removeClass("active"); }
                            }
                        });
                    }

                    $(this).addClass('active');
                    var filter = $(this).attr('data-filter');
                    recent.load();
                } else {
                    $(this).removeClass('active');
                    recent.load();
                }
            });

            recent = new Recent();
            recent.load();

            // Detect end of page scroll
            $(window).scroll(function() {
               if($(window).scrollTop() + $(window).height() == $(document).height()) {
                    if(!recent.empty_results) recent.lazy_load();
               }
            });

        });
    </script>

    <!-- IMPORT PAGE (import.html) -->
    <script type='text/javascript'>

        if(document.getElementById('analysis/import') !== null) {

            $(document)
                .on('change', '.btn-file :file', function() {
                    var input = $(this),
                    numFiles = input.get(0).files ? input.get(0).files.length : 1,
                    label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
                    input.trigger('fileselect', [numFiles, label]);
            });

            $(document).ready( function() {
                $('.btn-file :file').on('fileselect', function(event, numFiles, label) {

                    var input = $(this).parents('.input-group').find(':text'),
                        log = numFiles > 1 ? numFiles + ' files selected' : label;

                    if( input.length ) {
                        input.val(log);
                    } else {
                        if( log ) alert(log);
                    }

                });
            });

        }

    </script>

    <!-- WEBIF ANALYSIS  -->
    <script>

        $(document).ready(function(){

            $("#btn_screenshots_toggle").click(function(){
                $(this).parent().parent().parent().find('.panel-body').toggleClass("minified");
            });

            if($("table#network-hosts, table#network-dns").length) {

                setTimeout(function () {
                    ["network_hosts", "network_dns"].forEach(function (x) {
                        $('#' + x).DataTable({
                            responsive: true,
                            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
                            "pageLength": 10,
                            "language": {
                                "lengthMenu": "Show _MENU_ results",
                                "zeroRecords": "No results",
                                "info": "_PAGE_/_PAGES_"
                            }
                        });
                    });
                }, 200);

            }

        });

    </script>

</body>
</html>
